#!user/bin/env python3
# -- coding: utf-8 --
# @Createtime：2023/9/8 16:55
# @Updatetime：16:55
# @Author：Test008
# @File：6-其他内置对象
# @Description：
"""
python的内置方法有很多,内置方法也叫魔术方法
"""


# class Student:
#     def __init__(self, name, age):
#         self.name = name
#         self.age = age
#
#     # __str__字符串方法,使用__str__方法后,可以使类对象以字符串形式输出,不使用__str__内置方法会打印出内存地址
#     def __str__(self):
#         return f"输出Student类对象,name:{self.name},age:{self.age}"
#
#     # __lt__小于比较方法,用来比较类对象的属性大小,不使用lt方法是不能比较的
#     def __lt__(self, other):
#         return self.age < other.age
#
#     # __le__小于等于比较方法,lt方法没有的等于的比较
#     def __le__(self, other):
#         return self.age <= other.age
#
#     # __eq__等于比较
#     def __eq__(self, other):
#         return self.age == other.age
#
#
# stu1 = Student("明明", 12)
# stu2 = Student("芳芳", 10)
# stu3 = Student("迪迪", 10)
# __str__
# print(type(stu1))
# print(str(stu1))
# __lt__
# print(stu1 > stu2)
# print(stu1 < stu2)
# __le__
# print(stu1 >= stu2)
# print(stu1 <= stu2)
# __eq__
# print(stu2 == stu1)
# print(stu2 == stu3)

class GetInfo():
    def __init__(self, name, age):
        self.name = name
        self.age = age

    def __str__(self):
        return f"name:{self.name},age:{self.age}"

    def __lt__(self, other):
        # return self.age < other.age
        # return self.age = other.age
        return self.age < other.age  # 默认小于

    def __le__(self, other):
        # return self.age <= other.age
        return self.age <= other.age  # 默认小于等于

    def __eq__(self, other):
        return self.age == other.age  # 默认等于


stu1 = GetInfo("刘老四", 22)
stu2 = GetInfo("刘老四", 12)
print(stu1)
print(stu2 > stu1)
print(stu2 >= stu1)
print(stu2 == stu1)
